<!DOCTYPE html>
<html lang="en">





<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" type="image/png" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="My Personal Website For Blog">
  <meta name="author" content="黄宇辉">
  <meta name="keywords" content="learning note,hexo blog">
  <title>Python操作MySQL数据库之基本的CURD - 欢迎参观小灰灰的网站哟 ヾ(◍°∇°◍)ﾉﾞ ~</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/vs2015.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->
<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_yg9cfy8wd6.css">

<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">

<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
</head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>ANONYMOUS</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                Home
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                Archives
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                Tags
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                About
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="view intro-2" id="background" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container text-center white-text fadeInUp">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2019-11-15 20:56">
      November 15, 2019 pm
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      806 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      14
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <div class="post-content mx-auto" id="post">
            
            <article class="markdown-body">
              <h2 id="学习笔记-Python-操作-MySQL-数据库之基本的-CURD"><a href="#学习笔记-Python-操作-MySQL-数据库之基本的-CURD" class="headerlink" title="学习笔记 : Python 操作 MySQL 数据库之基本的 CURD"></a>学习笔记 : Python 操作 MySQL 数据库之基本的 CURD</h2><p><em>🐍 学习完 Python 的基础知识后，当然需要进阶地学习关于 Python 的数据库编程知识啦~ 下面是我写的一个操作 MySQL 数据库的基本增删改查，其对于和我一样初学 Python 的同学来说，非常具有参考与学习价值哟~</em></p>
<ol>
<li><em>tb_user : 数据库表结构</em><div class="hljs"><pre><code class="hljs sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`tb_user`</span> (
  <span class="hljs-string">`id`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> AUTO_INCREMENT,
  <span class="hljs-string">`name`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">45</span>) <span class="hljs-keyword">COLLATE</span> utf8mb4_unicode_ci <span class="hljs-keyword">DEFAULT</span> <span class="hljs-literal">NULL</span>,
  <span class="hljs-string">`sex`</span> <span class="hljs-built_in">char</span>(<span class="hljs-number">1</span>) <span class="hljs-keyword">COLLATE</span> utf8mb4_unicode_ci <span class="hljs-keyword">DEFAULT</span> <span class="hljs-literal">NULL</span>,
  <span class="hljs-string">`phone`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">45</span>) <span class="hljs-keyword">COLLATE</span> utf8mb4_unicode_ci <span class="hljs-keyword">DEFAULT</span> <span class="hljs-literal">NULL</span>,
  PRIMARY <span class="hljs-keyword">KEY</span> (<span class="hljs-string">`id`</span>)
) <span class="hljs-keyword">ENGINE</span>=<span class="hljs-keyword">InnoDB</span> AUTO_INCREMENT=<span class="hljs-number">9</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">CHARSET</span>=utf8mb4 <span class="hljs-keyword">COLLATE</span>=utf8mb4_unicode_ci</code></pre></div>


</li>
</ol>
<ol start="2">
<li><em>dbconfig.ini : 存储数据库的配置信息</em><div class="hljs"><pre><code class="hljs ini"><span class="hljs-section">[DATABASE_CONFIGURATION_INFOS]</span>
<span class="hljs-attr">host</span> = localhost
<span class="hljs-attr">user</span> = root
<span class="hljs-attr">password</span> = 
<span class="hljs-attr">database</span> = 
<span class="hljs-attr">charset</span> = utf8</code></pre></div>


</li>
</ol>
<ol start="3">
<li><em>Utils.py : 连接数据库的工具类</em><div class="hljs"><pre><code class="hljs python"><span class="hljs-string">"""
Project name : python-learning
Description : A SIMPLE TOOL FOR OPERATING DATABASE
Author : 黄宇辉
Version : 1.0
Website : https://yubuntu0109.github.io/
Created on 11/12/2019-9:30 PM
"""</span>

<span class="hljs-keyword">import</span> configparser
<span class="hljs-keyword">import</span> pymysql


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">DBUtils</span>:</span>

    <span class="hljs-string">"""
    get the databse configuration infos from the specified file
    """</span>
<span class="hljs-meta">    @staticmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">getConnConfig</span><span class="hljs-params">()</span>:</span>
        <span class="hljs-keyword">try</span>:
            configpar = configparser.ConfigParser()
            configpar.read(<span class="hljs-string">"dbconfig.ini"</span>, encoding=<span class="hljs-string">'utf-8'</span>)
            connConfig_items = dict(configpar.items(<span class="hljs-string">'DATABASE_CONFIGURATION_INFOS'</span>))
            <span class="hljs-keyword">return</span> connConfig_items

        <span class="hljs-keyword">except</span> FileNotFoundError <span class="hljs-keyword">as</span> e:
            print(<span class="hljs-string">"CATCH THE EXCEPTION INFO : %s"</span> % e)

    <span class="hljs-string">"""
    get the database connection object
    """</span>
<span class="hljs-meta">    @staticmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">getConnection</span><span class="hljs-params">()</span>:</span>
        <span class="hljs-keyword">try</span>:
            <span class="hljs-keyword">global</span> connection  <span class="hljs-comment"># defined a global connection object</span>
            connConfig = DBUtils.getConnConfig()  <span class="hljs-comment"># get the database configuration infos</span>
            connection = pymysql.connect(host=connConfig.get(<span class="hljs-string">'host'</span>),
                                         user=connConfig.get(<span class="hljs-string">'user'</span>),
                                         password=connConfig.get(<span class="hljs-string">'password'</span>),
                                         database=connConfig.get(<span class="hljs-string">'database'</span>),
                                         charset=connConfig.get(<span class="hljs-string">'charset'</span>))
            <span class="hljs-keyword">return</span> connection
        <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:
            print(<span class="hljs-string">"FAIL TO CONNECT TO THE DATABASE : %s"</span> % e)</code></pre></div>


</li>
</ol>
<ol start="4">
<li><em>CURD.py : 操作数据库的测试类</em><div class="hljs"><pre><code class="hljs python"><span class="hljs-string">"""
Project name : python-learning
Description : BASIC CURD ON MYSQL DATABASE
Author : 黄宇辉
Version : 1.0
Website : https://yubuntu0109.github.io/
Created on 11/11/2019-10:08 PM
"""</span>

<span class="hljs-keyword">import</span> pymysql
<span class="hljs-keyword">from</span> Utils <span class="hljs-keyword">import</span> DBUtils  <span class="hljs-comment"># format : from filename import classname</span>


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CURDTest</span>:</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-keyword">global</span> connection  <span class="hljs-comment"># defined a global variable</span>
        connection = DBUtils.getConnection()  <span class="hljs-comment"># get the database connection</span>

    <span class="hljs-string">"""
    select the specified user info by id
    """</span>
<span class="hljs-meta">    @classmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">selectById</span><span class="hljs-params">(cls, userid)</span>:</span>
        <span class="hljs-keyword">try</span>:
            <span class="hljs-comment"># create the cursor object</span>
            <span class="hljs-keyword">with</span> connection.cursor() <span class="hljs-keyword">as</span> cursor:
                <span class="hljs-comment"># defined the sql statement</span>
                sql = <span class="hljs-string">'SELECT id,name,sex,phone FROM tb_user WHERE id = %s'</span>
                <span class="hljs-comment"># execute the specified sql statement</span>
                cursor.execute(sql, [userid])
                <span class="hljs-comment"># get the result</span>
                row = cursor.fetchone()
                <span class="hljs-comment"># ouput the result</span>
                <span class="hljs-keyword">if</span> row <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">None</span>:
                    print(<span class="hljs-string">'ID:&#123;0&#125; - NAME:&#123;1&#125; - SEX:&#123;2&#125; - PHONE:&#123;3&#125;'</span>.format(row[<span class="hljs-number">0</span>], row[<span class="hljs-number">1</span>], row[<span class="hljs-number">2</span>], row[<span class="hljs-number">3</span>]))
                <span class="hljs-keyword">else</span>:
                    print(<span class="hljs-string">"NOT FOUND THE SPECIFIED USER INFO BY ID : %s"</span> % userid)

        <span class="hljs-comment"># catch the exception about database</span>
        <span class="hljs-keyword">except</span> pymysql.DatabaseError <span class="hljs-keyword">as</span> e:
            print(e)
        <span class="hljs-comment"># release the connection resource</span>
        <span class="hljs-keyword">finally</span>:
            connection.close()

    <span class="hljs-string">"""
    select all of user infos
    """</span>
<span class="hljs-meta">    @classmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">selectAll</span><span class="hljs-params">(cls)</span>:</span>
        <span class="hljs-keyword">try</span>:
            <span class="hljs-keyword">with</span> connection.cursor() <span class="hljs-keyword">as</span> cursor:
                sql = <span class="hljs-string">'SELECT id,name,sex,phone FROM tb_user'</span>
                cursor.execute(sql)
                result_set = cursor.fetchall()
                <span class="hljs-keyword">for</span> row <span class="hljs-keyword">in</span> result_set:
                    print(<span class="hljs-string">'ID:&#123;0&#125; - NAME:&#123;1&#125; - SEX:&#123;2&#125; - PHONE:&#123;3&#125;'</span>.format(row[<span class="hljs-number">0</span>], row[<span class="hljs-number">1</span>], row[<span class="hljs-number">2</span>], row[<span class="hljs-number">3</span>]))
        <span class="hljs-keyword">except</span> pymysql.DatabaseError <span class="hljs-keyword">as</span> e:
            print(e)
        <span class="hljs-keyword">finally</span>:
            connection.close()

    <span class="hljs-string">"""
    insert the user info
    """</span>
<span class="hljs-meta">    @classmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">addUser</span><span class="hljs-params">(cls, username, sex, telephone)</span>:</span>
        <span class="hljs-keyword">try</span>:
            <span class="hljs-keyword">with</span> connection.cursor() <span class="hljs-keyword">as</span> cursor:
                sql = <span class="hljs-string">'INSERT INTO tb_user(name,sex,phone) VALUE (%s,%s,%s)'</span>
                affectedcount = cursor.execute(sql, (username, sex, telephone))
                print(<span class="hljs-string">'inserted successfully and the affected count : %s'</span> % affectedcount)
                connection.commit()
        <span class="hljs-keyword">except</span> pymysql.DatabaseError <span class="hljs-keyword">as</span> e:
            print(e)
            connection.rollback()
        <span class="hljs-keyword">finally</span>:
            connection.close()

    <span class="hljs-string">"""
    update the user info
    """</span>
<span class="hljs-meta">    @classmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">updateUser</span><span class="hljs-params">(cls, username, sex, telephone, userid)</span>:</span>
        <span class="hljs-keyword">try</span>:
            <span class="hljs-keyword">with</span> connection.cursor() <span class="hljs-keyword">as</span> cursor:
                sql = <span class="hljs-string">'UPDATE tb_user SET name = %s, sex = %s, phone = %s WHERE id = %s'</span>
                affectedcount = cursor.execute(sql, (username, sex, telephone, userid))
                print(<span class="hljs-string">'updated successfully and the affected count : %s'</span> % affectedcount)
                connection.commit()
        <span class="hljs-keyword">except</span> pymysql.DatabaseError <span class="hljs-keyword">as</span> e:
            print(e)
            connection.rollback()
        <span class="hljs-keyword">finally</span>:
            connection.close()

    <span class="hljs-string">"""
    delete the user info
    """</span>
<span class="hljs-meta">    @classmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">delUser</span><span class="hljs-params">(cls, userid)</span>:</span>
        <span class="hljs-keyword">try</span>:
            <span class="hljs-keyword">with</span> connection.cursor() <span class="hljs-keyword">as</span> cursor:
                sql = <span class="hljs-string">'DELETE FROM tb_user WHERE id = %s'</span>
                affectedcount = cursor.execute(sql, userid)
                print(<span class="hljs-string">"deleted successfully and the affected count : %s"</span> % affectedcount)
                connection.commit()
        <span class="hljs-keyword">except</span> pymysql.DatabaseError <span class="hljs-keyword">as</span> e:
            print(e)
            connection.rollback()
        <span class="hljs-keyword">finally</span>:
            connection.close()


<span class="hljs-string">"""
test
"""</span>
curd = CURDTest()
curd.selectAll()
<span class="hljs-comment"># curd.selectById(userid=1)</span>
<span class="hljs-comment"># curd.addUser(username='addUser', sex='m', telephone='00000000000')</span>
<span class="hljs-comment"># curd.updateUser(username='updateUser', sex='f', telephone='11111111111', userid=1)</span>
<span class="hljs-comment"># curd.delUser(userid=1)</span></code></pre></div>


</li>
</ol>
<ol start="5">
<li><em>程序运行结果如下所示( 仅供参考 ) :</em><div class="hljs"><pre><code class="hljs groovy"><span class="hljs-string">ID:</span><span class="hljs-number">1</span> - <span class="hljs-string">NAME:</span>黄宇辉 - <span class="hljs-string">SEX:</span>男 - <span class="hljs-string">PHONE:</span><span class="hljs-number">11111111111</span>
<span class="hljs-string">ID:</span><span class="hljs-number">2</span> - <span class="hljs-string">NAME:</span>燕子 - <span class="hljs-string">SEX:</span>女 - <span class="hljs-string">PHONE:</span><span class="hljs-number">00000000000</span></code></pre></div>
</li>
</ol>

            </article>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/MySQL/">MySQL</a>
                    
                      <a class="hover-with-bg" href="/tags/Python/">Python</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" target="_blank" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <div class="post-prev col-6">
                    
                    
                      <a href="/2019/11/15/%E5%B0%86Kail-linux%E5%AE%8C%E7%BE%8E%E5%AE%89%E8%A3%85%E5%88%B0U%E7%9B%98-persistent-storage/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">将Kail linux完美安装到U盘( persistent storage )</span>
                        <span class="visible-mobile">Previous</span>
                      </a>
                    
                  </div>
                  <div class="post-next col-6">
                    
                    
                      <a href="/2019/11/08/hello-Python/">
                        <span class="hidden-mobile">hello Python</span>
                        <span class="visible-mobile">Next</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </div>
                </div>
              
            </div>

            
          </div>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;TOC</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">Search</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">keyword</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: 'article.markdown-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "Python操作MySQL数据库之基本的CURD&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  














</body>
</html>
